package top.interview

import problem.Problem

class Q136SingleNumber extends Problem {

  def singleNumber(nums: Array[Int]): Int = {
    nums.tail.foldLeft(nums.head) { (z, i) => z ^ i }
  }

  override def test(): Unit = {
    singleNumber(Array(2, 2, 1)) shouldBe 1
    singleNumber(Array(4, 1, 2, 1, 2)) shouldBe 4
  }
}
